package com.dnui.seven2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnui.seven2.common.R;
import com.dnui.seven2.entity.Crowdfunding;
import com.dnui.seven2.entity.Employee;
import com.dnui.seven2.service.CrowdfundingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/crowdfunding")
@Slf4j
public class CrowdfundingController {
    @Autowired
    private CrowdfundingService crowdfundingService;

    @GetMapping("/queryCrowdfundings}")
    public R<Page> queryPerformers( Integer currentPageNum, Integer everyPage ){
        Page pageInfo=new Page(currentPageNum,everyPage);
        //构造条件构造器
        LambdaQueryWrapper<Crowdfunding> queryWrapper=new LambdaQueryWrapper();

        //执行查询
        crowdfundingService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    @PostMapping("/saveCrowdfunding")
    public R<String> saveCrowdfunding(@RequestBody Crowdfunding crowdfunding){
        crowdfundingService.save(crowdfunding);
        return  R.success("添加成功");
    }

    @PutMapping("updateCrowdfunding")
    public R<String> updateCrowdfunding(@RequestBody Crowdfunding crowdfunding){
        crowdfundingService.updateCrowdfunding(crowdfunding);
        return  R.success("修改成功");
    }

    @DeleteMapping("deleteCrowdfunding/{crowdfundingId}")
    public R<String> deleteCrowdfunding(@PathVariable Long crowdfundingId){
        crowdfundingService.deleteCrowdfunding(crowdfundingId);
        return  R.success("删除成功");
    }

    @GetMapping("/getById/{crowdfundingId}")
    public R<Crowdfunding> getById(@PathVariable Long crowdfundingId){
        log.info("根据id查询员工信息");
        Crowdfunding crowdfunding=crowdfundingService.getById(crowdfundingId);
        return R.success(crowdfunding);
    }

    @GetMapping("/selectAll")
    public R<List<Crowdfunding>> selectAll(){
        List<Crowdfunding> crowdfundings = crowdfundingService.selectAll();
        return  R.success(crowdfundings);
    }
}
